package com.huilian.iotbox.admin.wap.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * MQConfig
 * 延迟队列配置器
 *
 * @Author mineChen
 * @Date 2021/3/23 21:15
 */
@Configuration
public class DelayMQConfig {

    /**
     * 延迟消息交换机
     */
    public static final String IOT_BOX_WAP_LAZY_EXCHANGE = "iotBox.wap_lazy_exchange";


    /**
     * 延迟队列
     */
    public static final String IOT_BOX_WAP_LAZY_QUEUE = "iotBox_wap_lazy_queue";
    /**
     * 延迟队列路由key
     */
    public static final String BOX_WAP_LAZY_QUEUE_KEY = "iotBox.wap_lazy_queue";


    /**
     * 活动开始状态，延迟队列
     */
    public static final String IOT_BOX_WAP_ACTIVITY_START_STATE_LAZY_QUEUE = "iotBox_wap_activity_start_state_lazy_queue";
    /**
     * 活动未开始————>开始，延迟队列路由key
     */
    public static final String IOT_BOX_WAP_ACTIVITY_START_STATE_LAZY_QUEUE_KEY = "iotBox_wap_activity_start_state_lazy_queue_key";


    /**
     * 活动结束状态，延迟队列
     */
    public static final String IOT_BOX_WAP_ACTIVITY_END_STATE_LAZY_QUEUE = "iotBox_wap_activity_end_state_lazy_queue";
    /**
     * 活动进行中————>结束，延迟队列路由key
     */
    public static final String IOT_BOX_WAP_ACTIVITY_END_STATE_LAZY_QUEUE_KEY = "iotBox_wap_activity_end_state_lazy_queue_key";

    /**
     * 图片上传未及时将文件名持久化到数据库过期处理。延迟队列
     */
    public static final String IOT_BOX_WAP_IMAGE_UPLOAD_DATE_PROCESSING_LAZY_QUEUE = "iotBox_wap_image_upload_date_processing_lazy_queue";
    /**
     * 图片上传未及时将文件名持久化到数据库过期处理。延迟队列路由key
     */
    public static final String IOT_BOX_WAP_IMAGE_UPLOAD_DATE_PROCESSING_LAZY_QUEUE_KEY = "iotBox_wap_image_upload_date_processing_lazy_queue_key";

    /**
     * 进件提交成功，删除资料缓存。延迟队列
     */
    public static final String IOT_BOX_WAP_MERCHANT_SUBMIT_REMOVE_INFO_LAZY_QUEUE = "iotBox_wap_merchant_submit_remove_info_lazy_queue";
    /**
     * 进件提交成功，删除资料缓存。延迟队列路由key
     */
    public static final String IOT_BOX_WAP_MERCHANT_SUBMIT_REMOVE_INFO_LAZY_QUEUE_KEY = "iotBox_wap_merchant_submit_remove_info_lazy_queue_key";

    /**
     * 延迟发送查询基础参数给外部设备。延迟队列
     */
    public static final String IOT_BOX_WAP_QUERY_EXTERNAL_DEVICE_PARAM_VALUE_LAZY_QUEUE = "iotBox_wap_query_external_device_param_value_lazy_queue";
    /**
     * 延迟发送查询基础参数给外部设备。延迟队列路由key
     */
    public static final String IOT_BOX_WAP_QUERY_EXTERNAL_DEVICE_PARAM_VALUE_LAZY_QUEUE_KEY = "iotBox_wap_query_external_device_param_value_lazy_queue_key";

    /**
     * 延迟发送查询基础参数给外部设备
     */
    public static final String IOT_BOX_WAP_SEND_MOTOR_DETECTION_LAZY_QUEUE = "iot_box_wap_send_motor_detection_lazy_queue";
    /**
     * 延迟发送查询基础参数给外部设备。延迟队列路由key
     */
    public static final String IOT_BOX_WAP_SEND_MOTOR_DETECTION_LAZY_QUEUE_KEY = "iot_box_wap_send_motor_detection_lazy_queue_key";


    @Bean
    public TopicExchange iotBoxWapLazyExchange() {
        Map<String, Object> pros = new HashMap<>();
        //设置交换机支持延迟消息推送
        pros.put("x-delayed-message", "topic");
        TopicExchange exchange = new TopicExchange(IOT_BOX_WAP_LAZY_EXCHANGE, true, false, pros);
        exchange.setDelayed(true);
        return exchange;
    }


    @Bean
    public Queue iotBoxWapLazyQueue() {
        return new Queue(IOT_BOX_WAP_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBoxWapLazyBinding() {
        return BindingBuilder.bind(iotBoxWapLazyQueue()).to(iotBoxWapLazyExchange()).with(BOX_WAP_LAZY_QUEUE_KEY);
    }


    @Bean
    public Queue iotBoxWapActivityStartStateLazyQueue() {
        return new Queue(IOT_BOX_WAP_ACTIVITY_START_STATE_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBoxWapActivityStartStateLazyBinding() {
        return BindingBuilder.bind(iotBoxWapActivityStartStateLazyQueue()).to(iotBoxWapLazyExchange()).with(IOT_BOX_WAP_ACTIVITY_START_STATE_LAZY_QUEUE_KEY);
    }


    @Bean
    public Queue iotBoxWapActivityEndStateLazyQueue() {
        return new Queue(IOT_BOX_WAP_ACTIVITY_END_STATE_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBoxWapActivityEndStateLazyBinding() {
        return BindingBuilder.bind(iotBoxWapActivityEndStateLazyQueue()).to(iotBoxWapLazyExchange()).with(IOT_BOX_WAP_ACTIVITY_END_STATE_LAZY_QUEUE_KEY);
    }


    @Bean
    public Queue iotBoxWapImageUploadDateProcessingLazyQueue() {
        return new Queue(IOT_BOX_WAP_IMAGE_UPLOAD_DATE_PROCESSING_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBoxWapImageUploadDateProcessingLazyBinding() {
        return BindingBuilder.bind(iotBoxWapImageUploadDateProcessingLazyQueue()).to(iotBoxWapLazyExchange()).with(IOT_BOX_WAP_IMAGE_UPLOAD_DATE_PROCESSING_LAZY_QUEUE_KEY);
    }


    @Bean
    public Queue iotBoxWapMerchantSubmitRemoveInfoLazyQueue() {
        return new Queue(IOT_BOX_WAP_MERCHANT_SUBMIT_REMOVE_INFO_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBoxWapMerchantSubmitRemoveInfoLazyBinding() {
        return BindingBuilder.bind(iotBoxWapMerchantSubmitRemoveInfoLazyQueue()).to(iotBoxWapLazyExchange()).with(IOT_BOX_WAP_MERCHANT_SUBMIT_REMOVE_INFO_LAZY_QUEUE_KEY);
    }

    /**
     * 以下配置为clien端需要
     */
    /**
     * 延迟消息交换机
     */
    public static final String IOT_BOX_CLIENT_LAZY_EXCHANGE = "iotBox.client_lazy_exchange";
    /**
     * 延迟队列路由key
     */
    public static final String BOX_CLIENT_LAZY_QUEUE_KEY = "iotBox.client_lazy_queue";

    @Bean
    public Queue iotBoxWapQueryExternalDeviceParamValueLazyQueue() {
        return new Queue(IOT_BOX_WAP_QUERY_EXTERNAL_DEVICE_PARAM_VALUE_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBoxWapQueryExternalDeviceParamValueLazyBinding() {
        return BindingBuilder.bind(iotBoxWapQueryExternalDeviceParamValueLazyQueue()).to(iotBoxWapLazyExchange()).with(IOT_BOX_WAP_QUERY_EXTERNAL_DEVICE_PARAM_VALUE_LAZY_QUEUE_KEY);
    }

    @Bean
    public Queue iotBoxWapSendMotorDetectionLazyQueue() {
        return new Queue(IOT_BOX_WAP_SEND_MOTOR_DETECTION_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBoxWapSendMotorDetectionLazyQueueValueLazyBinding() {
        return BindingBuilder.bind(iotBoxWapSendMotorDetectionLazyQueue()).to(iotBoxWapLazyExchange()).with(IOT_BOX_WAP_SEND_MOTOR_DETECTION_LAZY_QUEUE_KEY);
    }

}
